package com.parsechina.hpush.broker.parser;

import io.netty.handler.codec.mqtt.*;

/**
 * @author linfeng
 * @since 2016/11/22
 */
public final class MessageBuilder {

    private Object msg;

    public MessageBuilder(Object msg) {
        this.msg = msg;
    }

    /**
     * 转换为通用消息对象
     *
     * @return 通用推送消息
     */
    public PushMessage commonMessage() {
        return new PushMessage((MqttMessage) msg);
    }

    /**
     * 转换为连接消息
     *
     * @return 连接消息
     */
    public ConnectMessage connectMessage() {
        return new ConnectMessage((MqttConnectMessage) msg);
    }

    /**
     * 转换为连接响应消息
     *
     * @return 连接响应消息
     */
    public ConnAckMessage connAckMessage() {
        return new ConnAckMessage((MqttConnAckMessage) msg);
    }

    public DisconnectMessage disconnectMessage() {
        return new DisconnectMessage((MqttMessage) msg);
    }

    public PingReqMessage pingReqMessage() {
        return new PingReqMessage((MqttMessage) msg);
    }

    public PingRespMessage pingRespMessage() {
        return new PingRespMessage((MqttMessage) msg);
    }

    public PubAckMessage pubAckMessage() {
        return new PubAckMessage((MqttPubAckMessage) msg);
    }

    public PubCompMessage pubCompMessage() {
        return new PubCompMessage((MqttMessage) msg);
    }

    public PublishMessage publishMessage() {
        return new PublishMessage((MqttPublishMessage) msg);
    }

    public PubRecMessage pubRecMessage() {
        return new PubRecMessage((MqttMessage) msg);
    }

    public PubRelMessage pubRelMessage() {
        return new PubRelMessage((MqttMessage) msg);
    }

    public SubAckMessage subAckMessage() {
        return new SubAckMessage((MqttSubAckMessage) msg);
    }

    public SubscribeMessage subscribeMessage() {
        return new SubscribeMessage((MqttSubscribeMessage) msg);
    }

    public UnsubAckMessage unsubAckMessage() {
        return new UnsubAckMessage((MqttUnsubAckMessage) msg);
    }

    public UnsubscribeMessage unsubscribeMessage() {
        return new UnsubscribeMessage((MqttUnsubscribeMessage) msg);
    }

}
